package com.aqsare;

public class CalcNowPatt {
	 private long now_time = 0;

	 private  float val = 0;
	 private  boolean firstV = true;
	 private  long[] last_time  ;
	private indicator[] last_extrem ;
	private int max_patts=0;
	public pattern now_patt[];
	
	public CalcNowPatt ( int len, int maxlen){
		
		max_patts=maxlen;
		now_patt= new pattern[len];
	 last_time = new long[len];
	 last_extrem = new indicator[len];
	for (int i = 0; i < len; i++) {
		now_patt[i]= new pattern(0);
		now_patt[i].addPunct(new punct(0, 0));
		last_extrem[i] = new indicator(0, 0, 0,0);
		//last_extrem[i].setVal(my_sma[i].get(0).getVal());
		//last_time[i] = my_period[i].get(0).getTime();
		
	}
	
	
	
	}
	
public void firstVal(double val, long time){
for (int i = 0; i <last_extrem.length; i++) {

		
		
		last_extrem[i].setVal(val);
		last_time[i] = time;
		//now_patt[i].getPunct(0).setDtimp(dtimp)
	}
	}

public void newVal(int k, double val, long time){
	if (firstV) {
		
		firstVal( val, time);
		firstV=false;
	
	}
	else {
		last_extrem[k]=now_patt[k].addPunctMaxSize(new punct(now_patt[k].getPunct(
			now_patt[k].sizePatt() - 1).getDtimp()+ (int) (time - last_time[k])
			, now_patt[k].getPunct(now_patt[k].sizePatt() - 1).getDpip()+ (int) ((val - last_extrem[k].getVal())*100000)),max_patts, last_extrem[k]);

	
	
	}
	
	
}


}


/* 
 * 
 * 
 public void getCurrentPatt_learn_v1() {
		long now_time = 0;

		double val = 0;

		int[] last_index = new int[config.getPeriod().length];
		long[] last_time = new long[config.getPeriod().length];
		indicator[] last_extrem = new indicator[config.getPeriod().length];
		for (int i = 0; i < config.getPeriod().length; i++) {

			last_index[i] = 1;
			last_extrem[i] = new indicator(0, 0, 0);
			last_extrem[i].setVal(my_sma[i].get(0).getVal());
			last_time[i] = my_period[i].get(0).getTime();
			now_patt[i].addPunct(new punct(0, 0));
		}

		int max = 0;
		int trend = 0;

		long time = 0;
		my_plot.goPlot();
		
		// luam la rand toti indicii din cea mai mica M
		// in fuctie de timp incrementam indicele pe M superioare
		// adaugam in pattern punctul fata de punctul anterior +punctul anterior
		//
		int win_profit = 0;
		int lost_profit = 0;
		int no_orders=0;
		boolean current_order=false;
		for (int i = 1; i < my_sma[0].size(); i++) {

			val = my_sma[0].get(i).getVal();

			now_time = my_period[0].get(i).getTime();

			for (int k = 0; k < config.getPeriod().length - 1; k++) {
				if ((now_time < my_period[k].get(last_index[k]).getTime())||(k==0)) {
					now_patt[k].addPunctMaxSize(new punct(now_patt[k].getPunct(
							now_patt[k].sizePatt() - 1).getDtimp()+ (int) (now_time - last_time[k])
							, now_patt[k].getPunct(now_patt[k].sizePatt() - 1).getDpip()+ (int) ((val - last_extrem[k].getVal())*100000)));

					last_extrem[k].setVal(my_sma[k].get(last_index[k]).getVal());
					if(last_index[k]<my_sma[k].size()-2)last_index[k]++;
				
				
				 if ( (k==0) &&(now_patt[0].sizePatt()>2)){
					 my_plot.getCollector().getPunct().setDtimp(now_patt[0].getPunct(now_patt[0].sizePatt()-1).getDtimp());
					 my_plot.getCollector().getPunct().setDpip(now_patt[0].getPunct(now_patt[0].sizePatt()-1).getDpip());
				 }
				 
				}
				for (int w = 0; w < my_orders.size(); w++) {
					int delta=(int)((my_period[0].get(i).getOpen() - my_orders.get(w).getIn())*100000);
					int takeP=my_orders.get(w).getTp();
					int sellL=my_orders.get(w).getSl();
					
					if (( (delta *takeP ) > 0)&& ((delta* delta) >= (takeP*takeP))) {
						win_profit += (int)( (Math.sqrt(delta*delta)));
						//System.out.println("WWIN ###########close order! profit" +(int)( (Math.sqrt(delta*delta))));
						my_orders.remove(w);current_order=false;
						w--;
					} else if (((delta *takeP) <0 ) && ((delta* delta)  >=  (sellL* sellL))) {
						lost_profit = (int)(( Math.sqrt(delta*delta)));
						//System.out.println("LOST ###########close order! profit" +(int)( (Math.sqrt(delta*delta))));
						my_orders.remove(w);current_order=false;
						w--;

					}

				}
				
				int no_eq = 0;
				int eq_profit = 0;

				for (int w = 0; w < my_pattern[k].size(); w++) {
					if (now_patt[k].eq(my_pattern[k].get(w))) {
						if (no_eq > 0) {
							if (eq_profit * my_pattern[k].get(w).getAmpli() < 0) {
								no_eq = 0;
								break;
							} else {
								if (my_pattern[k].get(w).getAmpli()
										* my_pattern[k].get(w).getAmpli() > eq_profit
										* eq_profit)
									eq_profit = my_pattern[k].get(w).getAmpli();
							}
						} else {
							no_eq++;
							eq_profit = my_pattern[k].get(w).getAmpli();
						}

					}
				}

				// daca s-a asemanta cu un pattern sau mai multe si toate au
				// fost de acelasi T

				if ((no_eq > 0)&& (!current_order )){
					my_orders.add(new order(now_time, my_period[0].get(i)
							.getOpen(), eq_profit, config.getSLPoints()));
				//	System.out.println("new order! total orders" +my_orders.size());
					no_orders++; current_order=true;
				}

			}
			
			last_time[0] = now_time;

		}
		System.out.println("profit : " + win_profit);
		System.out.println("pierdere : " + lost_profit);
		System.out.println("profit total: " + (win_profit-lost_profit));
		System.out.println("no ordine : " + no_orders);
	}
		
 * 
 * */
